package com.lambert.ginkgo.dto;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty; /**
 * Usage statistics for the completion request.
 *
 * @param completionTokens Number of tokens in the generated completion. Only
 * applicable for completion requests.
 * @param promptTokens Number of tokens in the prompt.
 * @param totalTokens Total number of tokens used in the request (prompt +
 * completion).
 * @param promptTokensDetails Breakdown of tokens used in the prompt.
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public record Usage(// @formatter:off
                    @JsonProperty("completion_tokens") Integer completionTokens,
                    @JsonProperty("prompt_tokens") Integer promptTokens,
                    @JsonProperty("total_tokens") Integer totalTokens,
                    @JsonProperty("prompt_tokens_details") PromptTokensDetails promptTokensDetails) { // @formatter:on

    public Usage(Integer completionTokens, Integer promptTokens, Integer totalTokens) {
        this(completionTokens, promptTokens, totalTokens, null);
    }

    /**
     * Breakdown of tokens used in the prompt
     *
     * @param cachedTokens Cached tokens present in the prompt.
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonIgnoreProperties(ignoreUnknown = true)
    public record PromptTokensDetails(// @formatter:off
                                      @JsonProperty("cached_tokens") Integer cachedTokens) { // @formatter:on
    }
}
